#ifndef MODULE_GENERAL_REG_H
#define MODULE_GENERAL_REG_H

#include <module_header_reg.h>

#include <stdint.h>
//-------------- 1个字节 -------------------
//寄存器0x40：保留
typedef struct{
    union{
        struct{
            uint8_t a0     : 1;
            uint8_t a1     : 1;
            uint8_t a2     : 1;
            uint8_t a3     : 1;
            uint8_t        : 4;
        };
        uint8_t value;
        uint8_t data[1];
    };
}master_update_reg_t;

//-------------- 1个字节 -------------------
//寄存器 0x41：Motor(1-3)中断寄存器
typedef struct{
    union{
        struct{
            uint8_t a0     : 1;
            uint8_t a1     : 1;
            uint8_t a2     : 1;
            uint8_t a3     : 1;
            uint8_t        : 4;
        };
        uint8_t value;
        uint8_t data[1];
    };
}slave_interrupt_reg_t;

//-------------- 1个字节 -------------------
//寄存器 0x42：Motor(1-3)设置更新
typedef struct{
    union{
       struct{
            uint8_t a0     : 1;
            uint8_t a1     : 1;
            uint8_t a2     : 1;
            uint8_t a3     : 1;
            uint8_t        : 4;
        }setup;
        uint8_t value;
        uint8_t data[1];
    };
}slave_update_reg_t;

//-------------- 1个字节 -------------------
//寄存器 0x43：Motor(1-3) Motor使能
typedef struct{
    union{
        struct{
            uint8_t a0     : 1;
            uint8_t a1     : 1;
            uint8_t a2     : 1;
            uint8_t a3     : 1;
            uint8_t        : 4;
        };
        uint8_t value;
        uint8_t data[1];
    };
}slave_current_sample_channel_enable_reg_t;

//-------------- 1个字节 -------------------
//寄存器 0x44：Motor(1-3) Motor使能
typedef struct{
    union{
        struct{
            uint8_t a0     : 1;
            uint8_t a1     : 1;
            uint8_t a2     : 1;
            uint8_t a3     : 1;
            uint8_t        : 4;
        };
        uint8_t value;
        uint8_t data[1];
    };
}slave_current_sample_threshold_alarm_enable_reg_t;

//-------------- 2个字节 -------------------
//寄存器 0x48-0x49，0x4A-0x4B，0x4C-0x4D，0x4E-0x4F：CM-A0电流采样阈值和比较符
typedef struct{
    union{
        struct
        {
            uint16_t value:10;
            uint16_t      :2;
            uint16_t symbol:3;
            uint16_t      :1;
        };
        uint8_t data[2];
    };
}slave_current_sample_threshold_reg_t;

//-------------- 2个字节 -------------------
//寄存器 0x50-0x51，0x52-0x53，0x54-0x55，0x56-0x57：CM-A0电流采样值
typedef struct{
    union{
        uint16_t value;
        uint8_t data[2];
    };
}slave_current_sample_value_reg_t;

//-------------- 5个字节 -------------------
// 模块信息查询结构体定义
typedef struct 
{
    union{
        struct{
            slave_current_sample_value_reg_t                         slave_current_sample_value_reg;//2个字节:x4 = 8字节
            slave_current_sample_threshold_reg_t                   slave_current_sample_threshold_reg;//2个字节:x4 = 8字节
        };
        uint8_t data[4];
    };
}module_general_channel_t;


//-------------- 24个字节 -------------------
typedef struct
{
    union{
        struct
        {   
            master_update_reg_t                                                       master_update_reg;//1个字节：0x40
            slave_interrupt_reg_t                                                   slave_interrupt_reg;//1个字节：0x41
            slave_update_reg_t                                                         slave_update_reg;//1个字节：0x42
            slave_current_sample_channel_enable_reg_t                 current_sample_channel_enable_reg;//1个字节：0x43
            slave_current_sample_threshold_alarm_enable_reg_t current_sample_threshold_alarm_enable_reg;//1个字节：0x44
            module_reserved_reg_t                                               module_reserved_reg[3];//3个字节：0x45-0x46-0x47
            module_general_channel_t                                         module_general_channel[4];//4字节x4=16字节
        };
        
        uint8_t data[24];
    };
    
}module_general_reg_t;


typedef struct
{
    module_header_reg_t       module_header_reg;//40字节
    module_general_reg_t module_general_reg;//24字节
}module_reg_t;

#endif